home *** CD-ROM | disk | FTP | other *** search
- Path: sun001.spd.dsccc.com!spd!jmccarty
- From: jmccarty@spd.dsccc.com (Mike McCarty)
- Newsgroups: comp.lang.c
- Subject: Re: Confusion as to the proper use of MODULAS
- Date: 15 Feb 1996 19:24:27 GMT
- Organization: DSC Communications Corporation, Plano, Texas USA
- Message-ID: <4g019b$gvc@sun001.spd.dsccc.com>
- References: <4fr8be$ass@news.iconn.net> <31224679.6193@born.com> <4fthsu$1kl@ixnews7.ix.netcom.com>
- NNTP-Posting-Host: aplo139.spd.dsccc.com
-
- In article <4fthsu$1kl@ixnews7.ix.netcom.com>, KPN <wzjn@ix.netcom.com> wrote:
- )Confusion as to the proper use of MODULAS
- )
- )Very confused. Just as I think IÆve got it correct, I make-up a new
- )test, the results of which leave me mixed-up again.
- )
- )To begin with, this is the first rule I found out:
- )
- )Modulas operator simply shows: *** AFTER *** you divide, what is the
- )remainder?
- )EXAMPLE of this:
- ) 9 % 7 = ?
- ) 9 divided by 7 yields a remainder of 2
- ) 9 % 7 = 2
- )
- )1) MODULAS means divide a number and give me the left over number. OK -
- )not bad.
-
- [snip]
-
- )Here, begin my troubles: using MODULAS in an IF statement.
- )
- )I made up a test to see if a number I inputted was a 7. Sample code:
- )
- ) if (number % 7)
- ) printf("Not a 7\n");
- ) else
- ) printf("First integer was a 7\n");
- )
- )So, if the number WAS a 7, the ELSE would take over. OK. But, when I
- )enter in a ZERO, it still tells me that the number was a seven?
- )
- )Am I going in the right direction? Can someone tell me what IÆm doing
- )incorrectly, or where IÆm straying? WhatÆs the rule here for using MOD
- )in an IF statement?
-
- You used it just fine. You just still don't exactly understand what a
- remainder is. You are testing for divisibility. Zero (0) is exactly
- divisible by 7 (or any other non-zero number, for that matter), with no
- remainder. In fact,
-
- 0 = (0)(7)+(0)
-
- And since |0| <= |0| (absolute of remainder less or equal to absolute of
- divisor), 0 is the remainder.
-
- So 0 is a multiple of 7. So is 14. So 14 % 7 is 0.
-
- Mike
- ----
- char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
-
- I don't speak for DSC. <- They make me say that.
-